<?php
header('Content-type: application/json;charset=utf-8');
require_once(dirname(__FILE__) . '/../include/config.inc.php');
require_once "function.php";
//获取 post的json数据
//获取 goodsid
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
$op = htmlspecialchars($_POST['op']);
$post_time2 = date("Y-m-d H:i:s", time());
$nowdate = date("Ymd", time());
if (isset($id)) {
    $time = time();
    //获取工单的时间
    $k = $dosql->GetOne("select * from `#@__project` where id='$id'");
    $post_time = $k['post_time'] + 1800;
    $jindu = $k['jindu'];
    $old_manageid = $k['manageid'];
    $old_pmid = $k['pmid'];
    $signInTime = $k['signInTime'];
    $signIn = $k['signIn'];
    $old_fee = $k['fee'];
    $old_apply_device = $k['apply_device'];
    $projectname = $k['projectname'];
    $school = $k['school'];
    $int_address = $k['address'];
    $end_time_init = $k['endtime'];
    $oktime2_init = $k['oktime2'];
    $shigongjihua = $k['planpicurls'];
    $p_area = $k['area']; //施工区域
    //获取工程师的 列表
    if ($op == 'getUser') {
        $manageid = $k['manageid'];
        //修改订单状态
        $return_str = "";
        if ($manageid != "") {
            $manageid_arr = explode(",", $manageid);
            foreach ($manageid_arr as $key => $val) {
                $return_str .= '<label class="radio-inline"><input name="qiantui2" id="qiantui2" type="radio" value="' . $val . '">' . getManage($val) . "</label>";
            }
        }
        $jssdk->return_json_body(['code' => 0, 'msg' => 'success', 'data' => $return_str]);
    }
    //接单
    if ($op == 'jiedan') {
        //判断是否超时
        if ($jindu == '3') {
            $manageid = $_POST['pmid'];
            //修改订单状态
            $dosql->ExecNoneQuery("update  `#@__project` set jindu='4' where id='$id' ");
            //记录工单操作
            $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,pmid,jiedan,latitude,longitude,accuracy,address,address_name) values ('$id','项目经理接单','$time','4','$manageid','1','$latitude','$longitude','$accuracy','$address','$address_name')");
            $jssdk->return_json_body(['code' => 0, 'msg' => '接单成功']);
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //工程撤单
    if ($op == 'chedan') {
        //判断是否超时
        if ($jindu == '3' || $jindu == '4') {
            $manageid = $_POST['pmid'];
            //修改订单状态
            $dosql->ExecNoneQuery("update  `#@__project` set jindu='0' where id='$id' ");
            //记录工单操作
            $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,pmid,jiedan,latitude,longitude,accuracy,address,address_name,op_manageid) values ('$id','管理员进行工程撤单','$time','4','$manageid','1','$latitude','$longitude','$accuracy','$address','$address_name','$uid')");
            $jssdk->return_json_body(['code' => 0, 'msg' => '工程撤单成功']);
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //工程竣工
    if ($op == 'over') {
        //判断是否超时
        if ($jindu == '4') {
            // 判断是否上传施工进度
            $sdefaultDate = date("Y-m-d");
            //$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
            $first=1;
            //获取当前周的第几天 周日是 0 周一到周六是 1 - 6
            $w=date('w',strtotime($sdefaultDate));
            //获取本周开始日期，如果$w是0，则表示周日，减去 6 天
            $week_start=date('Y-m-d',strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days'));
            $week_start_time=strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days');
            //本周结束日期
            $week_end=strtotime("$week_start +6 days")+86399;
            $report_Arr = $dosql->GetOne("select `id` from  `#@__project_log`  WHERE orderid='$id' and wreport=1 and op_time>$week_start_time and op_time<$week_end  ");
            if(!$report_Arr){
                $jssdk->return_json_body(['code' => 2, 'msg' => '请先上传本周的施工进度']);
            }
            if ($pmid == $uid) {
                $pic_json_arr = "";
                $pic_str = isset($_POST['picfiles']) ? htmlspecialchars($_POST['picfiles']) : "";
                if ($pic_str != "") {
                    $picarr = explode(",", $pic_str);
                    $pic_json_arr = json_encode($picarr);
                }
                //修改订单状态
                $dosql->ExecNoneQuery("update  `#@__project` set jindu='5',over_time='$time',over_remark='$remark',keyInfo='$keyInfo',over_picurls='$pic_json_arr',latitude2='$latitude',longitude2='$longitude',accuracy2='$accuracy' where id='$id' ");
                //记录工单操作
                $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,pmid,jiedan,latitude,longitude,accuracy,address,address_name,remark) values ('$id','项目竣工','$time','5','$pmid','1','$latitude','$longitude','$accuracy','$address','$address_name','$remark')");
                //给管理员发送 验收提醒
                $openid_str = getManageOpenidFromUid(1);
                $send_body['touser'] = $openid_str;
                $send_body['template_id'] = $cfg_yanshou;
                $send_body['url'] = $cfg_weburl . 'wx/projectDetail.php?projectid=' . $id;
                $send_body['data']['first']['value'] = "项目【" . $projectname . "】已经提交竣工申请。请点击设置验收时间";
                $send_body['data']['first']['color'] = "#FF0000";
                $send_body['data']['keyword1']['value'] = "【" . getManage($pmid) . "】提交工程竣工申请";
                $send_body['data']['keyword1']['color'] = "#173177";
                $send_body['data']['keyword2']['value'] = $post_time2;
                $send_body['data']['keyword2']['color'] = "#FF0000";
                $send_body['data']['keyword3']['value'] = "💗" . $school . "-" . $address;
                $send_body['data']['keyword3']['color'] = "#0e48cb";
                $send_body['data']['remark']['value'] = $remark;
                $send_body['data']['remark']['color'] = "#FF0000";
                $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                $res = $jssdk->https_curl_json($url, $send_body, 'json');
                //计算竣工奖励
                $today = date("Y-m-d");
                $today_datatime = date_create($today);
                $end_time = date("Y-m-d", $end_time_init);
                $end_datatime = date_create($end_time);
                $day_diff = date_diff($today_datatime, $end_datatime);
                $day_diff = $day_diff->format("%R%a");
                $day_diff = intval($day_diff);
                if ($day_diff > 0) {
                    $day_diff_fee = $day_diff * $cfg_tiqianjungong;
                    //奖励项目经理
                    //插入 奖励记录
                    $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,remark,fee,task) values ('project','$id','add','$time','4','$pmid','项目提前竣工，项目经理 计算奖励','$day_diff_fee','$old_apply_device')");
                    //增加奖励计划
                    $dosql->ExecNoneQuery("update  `#@__user` set fee=fee+'$day_diff_fee' where id='$pmid' ");
                }
                $jssdk->return_json_body(['code' => 0, 'msg' => '项目竣工']);
            } else {
                $jssdk->return_json_body(['code' => 2, 'msg' => '对不起，你不是项目经理']);
            }
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //签到
    if ($op == 'signIn') {
        //判断是否超时
        if ($jindu == '4') {
            $manageids = $_POST['manageids'];
            $pic_json_arr = "";
            $pic_str = isset($_POST['picfiles']) ? htmlspecialchars($_POST['picfiles']) : "";
            if ($pic_str != "") {
                $picarr = explode(",", $pic_str);
                $pic_json_arr = json_encode($picarr);
            }
            $apply_device = isset($_POST['apply_device']) ? intval($_POST['apply_device']) : 0;
            $fee = getFeeFromType($apply_device);
            //修改订单状态
            $dosql->ExecNoneQuery("update  `#@__project` set signIn='1',signInTime='$time',manageid='$manageids',apply_device='$apply_device',fee='$fee' where id='$id' ");
            // 判断是否迟到
            // date_format(from_unixtime(create_time),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d');
            $now_hour = date("H", time());
            $now_hour=intval($now_hour);
            if ($now_hour < 12 ) {
                $chidaoshijian = strtotime("$nowdate 8:30:00");
                if ($p_area == "town") {
                    $chidaoshijian = strtotime("$nowdate 9:00:00");
                }
                if ($chidaoshijian < time()) {
                    $sign_Arr = $dosql->GetOne("select `id` from  `#@__project_log`  WHERE orderid='$id' and signIn=1 and date_format(from_unixtime(op_time),'%Y-%m-%d') = date_format(now(),'%Y-%m-%d') ");
                    if (is_array($sign_Arr) && isset($sign_Arr['id']) ) {
                    }else{
                        $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,remark,fee,task,feetype,nowdate) values ('project','$id','move','$time','4','$pmid','项目签到异常，项目经理 处罚','$cfg_qiandaoyichang','$old_apply_device','qiandaoyichang','$nowdate')");
                    }
                }
            }
            //是否上传施工计划
            if ($shigongjihua == "") {
                //判断是否处罚施工计划
                $sign_Arr = $dosql->GetOne("select `id` from  `#@__fee_log`  WHERE orderid='$id' and `type`='project' and  feetype='shigongjihua'  ");
                if (!$sign_Arr) {
                    $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,remark,fee,task,feetype,nowdate) values ('project','$id','move','$time','4','$pmid','项目施工前未上传施工计划，项目经理 处罚','$cfg_shigongjihua','$old_apply_device','shigongjihua','$nowdate')");
                }
            }
            //记录工单操作
            $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,manageid,signIn,latitude,longitude,accuracy,address,address_name,pmid,remark,op_manageid,picurls,apply_device) values ('$id','项目经理施工签到','$time','4','$manageids','1','$latitude','$longitude','$accuracy','$address','$address_name','$pmid','$remark','$uid','$pic_json_arr','$apply_device')");
            $jssdk->return_json_body(['code' => 0, 'msg' => '签到成功']);
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //设置第二项目经理
    if ($op == 'setPM2') {
        //判断是否超时
        if ($jindu < 6) {
            $pmid2 = $_POST['manageid'];
            //修改订单状态
            $dosql->ExecNoneQuery("update  `#@__project` set pmid2='$pmid2' where id='$id' ");
            $op_name = "设置第二项目经理" . getManage($pmid2);
            //记录工单操作
            $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,manageid,setpm2,latitude,longitude,accuracy,address,address_name,pmid,remark,op_manageid) values ('$id','$op_name','$time','4','$pmid2','1','$latitude','$longitude','$accuracy','$address','$address_name','$pmid','$remark','$uid')");
            //给 第二产品叫你过来 发送 提醒
            $openid_str = getManageOpenidFromUid($pmid2);
            $send_body['touser'] = $openid_str;
            $send_body['template_id'] = 'zPJvA6I2M1o2YbJMpG2gDYcwmapuWGqzBsVD_AXgajk';
            $send_body['url'] = $cfg_weburl . 'wx/projectDetail.php?projectid=' . $id;
            $send_body['data']['first']['value'] = "项目经理" . getManage($pmid) . "设置第二项目经理 ,请点击进行项目管理。";
            $send_body['data']['first']['color'] = "#FF0000";
            $send_body['data']['keyword1']['value'] = $projectname;
            $send_body['data']['keyword1']['color'] = "#173177";
            $send_body['data']['keyword2']['value'] = getRepairMode($old_apply_device);
            $send_body['data']['keyword2']['color'] = "#FF0000";
            $send_body['data']['keyword3']['value'] = getManage($pmid);
            $send_body['data']['keyword4']['value'] = $remark;
            $send_body['data']['remark']['value'] = "请协助项目经理进行工程管理。";
            $send_body['data']['remark']['color'] = "#FF0000";
            $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
            $res = $jssdk->https_curl_json($url, $send_body, 'json');
            $jssdk->return_json_body(['code' => 0, 'msg' => '设置成功']);
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //人员中途签退
    if ($op == 'qiantui2') {
        //判断是否超时
        if ($jindu == '4') {
            $manageid = $_POST['manageid'];
            $pmid = $_POST['pmid'];
            //从数组中删除这个员工id
            $new_str = "";
            if ($old_manageid != "") {
                $new_manageid_arr = explode(",", $old_manageid);
                $arr = array_merge(array_diff($new_manageid_arr, array($manageid)));
                if (isset($arr)) {
                    $new_str = implode(",", $arr);
                }
            }
            //修改订单状态
            $dosql->ExecNoneQuery("update  `#@__project` set jindu='4',manageid='$new_str' where id='$id' ");
            //记录工单操作
            $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,pmid,zhongtu,latitude,longitude,accuracy,address,address_name,manageid,op_manageid) values ('$id','施工人员中途签退','$time','4','$pmid','1','$latitude','$longitude','$accuracy','$address','$address_name','$manageid','$uid')");
            //计算 费用
            $fee = autoSumFee($old_fee, $signInTime, $cfg_jiabanfei);
            $fee_time = time();
            //插入 奖励记录
            $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,remark,fee,task) values ('project','$id','add','$fee_time','4','$manageid','施工人员中途签退 计算奖励','$fee','$old_apply_device')");
            //增加奖励计划
            $dosql->ExecNoneQuery("update  `#@__user` set fee=fee+'$fee' where id='$manageid' ");
            $jssdk->return_json_body(['code' => 0, 'msg' => '人员中途签退成功']);
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //签退
    if ($op == 'qiantui') {
        //判断是否超时
        if ($jindu == '4') {
            $manageids = $old_manageid;
            $pic_json_arr = "";
            $pic_str = isset($_POST['picfiles']) ? htmlspecialchars($_POST['picfiles']) : "";
            if ($pic_str != "") {
                $picarr = explode(",", $pic_str);
                $pic_json_arr = json_encode($picarr);
            }
            //修改订单状态
            $dosql->ExecNoneQuery("update  `#@__project` set signIn='0',signInTime=0 where id='$id' ");
            //记录工单操作
            $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,manageid,qiantui,latitude,longitude,accuracy,address,address_name,pmid,remark,op_manageid,picurls) values ('$id','项目经理施工签退','$time','4','$manageids','1','$latitude','$longitude','$accuracy','$address','$address_name','$pmid','$remark','$uid','$pic_json_arr')");
            //增加 任务奖励
            $m2_arr = explode(",", $manageids);
            foreach ($m2_arr as $key => $val) {
                //计算 费用
                $fee = autoSumFee($old_fee, $signInTime, $cfg_jiabanfei);
                //插入 奖励记录
                $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,remark,fee,task) values ('project','$id','add','$time','4','$val','施工人员正常签退 计算奖励','$fee','$old_apply_device')");
                //增加奖励计划
                $dosql->ExecNoneQuery("update  `#@__user` set fee=fee+'$fee' where id='$val' ");
            }
            $jssdk->return_json_body(['code' => 0, 'msg' => '签退成功']);
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //发起验收通知
    if ($op == 'addcheck') {
        //判断是否超时
        if ($jindu == '5') {
            if ($isadmin == 1) {
                $begintime_date = htmlspecialchars($_POST['beginTime']);
                $endtime_date = htmlspecialchars($_POST['endTime']);
                $begintime = strtotime($begintime_date);
                $endtime = strtotime($endtime_date)+86399;
                $checkbook = htmlspecialchars($_POST['checkbook']);
                //修改订单状态
                $dosql->ExecNoneQuery("update  `#@__project` set jindu='6',oktime='$begintime',oktime2='$endtime',checkbook='$checkbook' where id='$id' ");
                //记录工单操作
                $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,pmid,addcheck,remark,op_manageid) values ('$id','发起验收通知','$time','6','$old_pmid','1','$checkbook','$uid')");
                //给管理员发送 验收提醒
                $dosql->Execute("SELECT `openid` FROM  `#@__user`  WHERE isadmin=1 or id='$old_pmid'  ORDER BY id asc");
                while ($row_admin = $dosql->GetArray()) {
                    $openid_str = $row_admin['openid'];
                    $send_body['touser'] = $openid_str;
                    $send_body['template_id'] = $cfg_yanshoutixing;
                    $send_body['url'] = $cfg_weburl . 'wx/projectDetail.php?projectid=' . $id;
                    $send_body['data']['first']['value'] = "项目【" . $projectname . "】,管理员已经发起验收流程。";
                    $send_body['data']['first']['color'] = "#FF0000";
                    $send_body['data']['keyword1']['value'] = $projectname;
                    $send_body['data']['keyword1']['color'] = "#173177";
                    $send_body['data']['keyword2']['value'] = $begintime_date . "~" . date("Y-m-d", $endtime);
                    $send_body['data']['keyword2']['color'] = "#FF0000";
                    $send_body['data']['remark']['value'] = "请在规定时间内积极联系甲方验收，提前验收有奖励哦。";
                    $send_body['data']['remark']['color'] = "#FF0000";
                    $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                    $res = $jssdk->https_curl_json($url, $send_body, 'json');
                }
                $jssdk->return_json_body(['code' => 0, 'msg' => '发起验收成功']);
            } else {
                $jssdk->return_json_body(['code' => 2, 'msg' => '对不起，你不是项目经理']);
            }
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //工程验收通过
    if ($op == 'checkok') {
        //判断是否超时
        if ($jindu == '6') {
            $manageids = $_POST['manageids'];
            $pic_json_arr = "";
            $pic_str = isset($_POST['picfiles']) ? htmlspecialchars($_POST['picfiles']) : "";
            if ($pic_str != "") {
                $picarr = explode(",", $pic_str);
                $pic_json_arr = json_encode($picarr);
            }
            $apply_device = isset($_POST['apply_device']) ? intval($_POST['apply_device']) : 0;
            $fee = getFeeFromType($apply_device);
            //修改订单状态
            $dosql->ExecNoneQuery("update  `#@__project` set jindu='7',checktime='$time',checkcontent='$remark',checkpicfiles='$pic_json_arr' where id='$id' ");
            //记录工单操作
            $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,manageid,checkok,latitude,longitude,accuracy,address,address_name,pmid,remark,op_manageid,picurls,apply_device) values ('$id','工程验收通过','$time','7','$manageids','1','$latitude','$longitude','$accuracy','$address','$address_name','$pmid','$remark','$uid','$pic_json_arr','$apply_device')");
            //记录奖励
            //增加 任务奖励
            $zhixingren = "";
            $m2_arr = explode(",", $manageids);
            foreach ($m2_arr as $key => $val) {
                //计算 费用
                $zhixingren .= getManage($val);
                //插入 奖励记录
                $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,remark,fee,task) values ('project','$id','add','$time','4','$val','验收项目 计算奖励','$fee','$apply_device')");
                //增加奖励计划
                $dosql->ExecNoneQuery("update  `#@__user` set fee=fee+'$fee' where id='$val' ");
            }
            //给管理员发送 验收通 提醒
            $dosql->Execute("SELECT `openid` FROM  `#@__user`  WHERE isadmin=1 or id='$old_pmid'   ORDER BY id asc");
            while ($row_admin = $dosql->GetArray()) {
                $openid_str = $row_admin['openid'];
                $send_body['touser'] = $openid_str;
                $send_body['template_id'] = $cfg_yanshoutongguo;
                $send_body['url'] = $cfg_weburl . 'wx/projectDetail.php?projectid=' . $id;
                $send_body['data']['first']['value'] = "项目【" . $projectname . "】,验收通过。";
                $send_body['data']['first']['color'] = "#FF0000";
                $send_body['data']['keyword1']['value'] = $projectname;
                $send_body['data']['keyword1']['color'] = "#173177";
                $send_body['data']['keyword2']['value'] = $zhixingren;
                $send_body['data']['keyword2']['color'] = "#FF0000";
                $send_body['data']['keyword3']['value'] = $post_time2;
                $send_body['data']['remark']['value'] = "验收通过，请知悉。";
                $send_body['data']['remark']['color'] = "#FF0000";
                $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $g_AccessToken;
                $res = $jssdk->https_curl_json($url, $send_body, 'json');
            }
            $today = date("Y-m-d");
            $today_datatime = date_create($today);
            $end_time = date("Y-m-d", $oktime2_init);
            $end_datatime = date_create($end_time);
            $day_diff = date_diff($today_datatime, $end_datatime);
            $day_diff = $day_diff->format("%R%a");
            $day_diff = intval($day_diff);

            //计算 验收  奖励
            if ($time < $oktime2_init) {
                $day_diff_fee = $day_diff*$cfg_tiqianyanshou;
                //奖励项目经理
                //插入 奖励记录
                $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,remark,fee,task,feetype,nowdate) values ('project','$id','add','$time','4','$pmid','项目提前验收通过，项目经理 计算奖励','$day_diff_fee','$old_apply_device','tiqianyanshou','$nowdate')");
                //增加奖励计划
                $dosql->ExecNoneQuery("update  `#@__user` set fee=fee+'$day_diff_fee' where id='$pmid' ");
            } else {
                $day_diff_fee =  $day_diff*$cfg_yanqiyanshou;
                $dosql->ExecNoneQuery("insert into `#@__fee_log`(`type`,orderid,op,op_time,jindu,manageid,remark,fee,task,feetype,nowdate) values ('project','$id','move','$time','4','$pmid','项目延期验收通过，项目经理 处罚','$day_diff_fee','$old_apply_device','yanshouyuqi','$nowdate')");
                //增加奖励计划
                $dosql->ExecNoneQuery("update  `#@__user` set fee=fee+'$day_diff_fee' where id='$pmid' ");
            }
            $jssdk->return_json_body(['code' => 0, 'msg' => '操作成功']);
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //上传施工计划
    if ($op == 'plan') {
        //判断是否是项目经理
        if ($pmid == $uid) {
            $pic_json_arr = "";
            $pic_str = isset($_POST['picfiles']) ? htmlspecialchars($_POST['picfiles']) : "";
            if ($pic_str != "") {
                $picarr = explode(",", $pic_str);
                $pic_json_arr = json_encode($picarr);
            }
            //修改订单状态
            $dosql->ExecNoneQuery("update  `#@__project` set planpicurls='$pic_json_arr' where id='$id' ");
            //记录工单操作
            $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,pmid,plan,latitude,longitude,accuracy,address,address_name,remark,picurls) values ('$id','上传施工计划','$time','4','$pmid','1','$latitude','$longitude','$accuracy','$address','$address_name','$remark','$pic_json_arr')");
            $jssdk->return_json_body(['code' => 0, 'msg' => '上传施工计划成功']);
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
    //上传周总汇
    if ($op == 'report') {
        //判断是否是项目经理
        if ($pmid == $uid) {
            $pic_json_arr = "";
            $pic_str = isset($_POST['picfiles']) ? htmlspecialchars($_POST['picfiles']) : "";
            if ($pic_str != "") {
                $picarr = explode(",", $pic_str);
                $pic_json_arr = json_encode($picarr);
            }
            //记录工单操作
            $dosql->ExecNoneQuery("insert into `#@__project_log`(orderid,op,op_time,jindu,pmid,wreport,latitude,longitude,accuracy,address,address_name,remark,picurls) values ('$id','上传施工周汇总','$time','4','$pmid','1','$latitude','$longitude','$accuracy','$address','$address_name','$remark','$pic_json_arr')");
            $jssdk->return_json_body(['code' => 0, 'msg' => '上传周汇总成功']);
        } else {
            $jssdk->return_json_body(['code' => 1, 'msg' => '状态错误，请重试']);
        }
    }
}
?>
